
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">批量发货</h4>
            </div>
            <div class="modal-body">

                <div class="bs-example bs-example-tabs">
                    <ul id="myTab" class="nav nav-tabs">
                        <li class="active"><a href="#nloprinteorder" onclick="$('.kd_type').val(3);" data-toggle="tab">批量发货</a>
                        </li>
                        <li><a href="#nlogistics" onclick="addorder()" data-toggle="tab">无需物流</a></li>
                    </ul>
                    <input type="hidden" name="kd_type" class="kd_type" value="3"/>
                    <div id="myTabContent" class="tab-content">
                        <div class="tab-pane m-t fade in active layui-form" id="nloprinteorder" style="overflow:hidden;">
                            <div class="form-group layui-form-item">
                                <label class="layui-form-label">模板：</label>
                                <form action="{:url('newbatchShipping')}" class="talbe-search layui-input-block" >
                                    <button type="button" class="layui-btn" id="upfilexlsx" onclick="evalOrderids()"><i class="layui-icon">&#xe601;</i>下载没发货订单表</button>
                                </form>
                                
                            </div>
                           
                            <div class="form-group layui-form-item">
                                <label class="layui-form-label">导入：</label>
                                <div id="fileId" class="layui-input-block talbe-search2">
                                  <!--<input type="text" id="avatval" readonly="readonly" style="vertical-align: middle;" placeholder="请选择导入的Excel文件"/>-->
                                  <button type="button" class="layui-btn layui-btn-normal" style="position: relative; ">
                                      <div style="position: absolute; width: 80%">
                                          <i class="layui-icon">&#xe621;</i>
                                          <span id="fileText">请选择导入的Excel文件</span>
                                      </div>
                                      <input type="file" name="excel" class="Js_file-input" id="avatar" style="opacity: 0"/>
                                  </button>
                                  
                                  <button type="sumbit" class="layui-btn" onclick="evalOrderids2()"><i class="layui-icon"></i>提交</button>
                              </div>
                          </div> 

                        </div>
                        <div class="tab-pane m-t fade" id="nlogistics"><p>如果该物品无需物流运送(如虚拟产品)</p></div>

                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <input type="hidden" id="order_ids"  value="" name="order_ids"/>
                <!-- <button type="submit" class="btn btn-primary" data-loading-text="保存中..." >保存</button> -->
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
       
        </div>
    </div>
<link rel="stylesheet" href="__STATIC__/layui/css/layui.css"  media="all">

<script type="text/javascript">
    $(function(){
        setTimeout(()=>{
            $(".Js_file-input").on("change",function (e) {
                console.log('监听',e)
              var e = e || window.event;
              //获取 文件 个数 取消的时候使用
              var files = e.target.files;
              if(files.length>0){
                  // 获取文件名 并显示文件名
                  var fileName = files[0].name;
                  console.log('fileName',fileName)
                  document.getElementById('fileText').innerHTML = fileName

              }else{
                  //清空文件名
                  document.getElementById('fileText').innerHTML = '请选择导入的Excel文件'
              }
            }); 
        }, 100)
        
        $("#avatsel").click(function(){
            $("input[type='file']").trigger('click');
        });
        $("#avatval").click(function(){
            $("input[type='file']").trigger('click');
        });
        $("input[type='file']").change(function(){
            $("#avatval").val($(this).val());
        });
    });
</script>

<script src="__STATIC__/layui/layui.js" charset="utf-8"></script>
<script type="text/javascript">

    function evalOrderids(){
        var sel_order = [];
        $('input[name="order_id"]').each(function () {
            if ($(this).is(':checked')) {
                sel_order.push($(this).val());
            }
        });
        console.log(sel_order)
        if (sel_order.length < 1) {
            _alert('请勾选需要发货的订单.');
            $('.modal-dialog').find('.close').click();
        }
        $('#order_ids').val(sel_order.join(','));
        //调用下载文件按钮
        var arr = new Object();
        arr.order_ids = sel_order.join(',')
        $('.talbe-search').append('<input type="hidden" name="is_export" id="is_export" value="1">').submit();
        $('#is_export').remove();
        

    }
    function evalOrderids2(){
        $('.talbe-search2').append('<input type="hidden" name="is_export2" id="is_export2" value="1">')
        $('#is_export2').remove();
        const file = $("#avatar")[0].files[0]
        if (!file) {
            return  layer.msg('请先上传文件！'); 
        }
        if (!file.name.includes('.xls')) {
            return  layer.msg('请上传xls文件！'); 
        }
        console.log('file',file)
        const formData = new FormData();
        formData.append("excel", $("#avatar")[0].files[0]);
        $.ajax({
            url : "{:url('upfilebatchShipping')}", 
            type: 'POST',
            data: formData,
            dataType: 'json',
            contentType:false,
            processData:false,
            success: function(res){
                layer.open({
                  title: '导入结果'
                  ,content: res.msg
                }); 
            },
            error: function(err){
                layer.msg('上传失败');
            },
        });
    }
    function addorder(){
        $('.kd_type').val(2);
        var sel_order = [];
        $('input[name="order_id"]').each(function () {
            if ($(this).is(':checked')) {
                sel_order.push($(this).val());
            }
        });
        if (sel_order.length < 1) {
            _alert('请勾选需要发货的订单2.');
            $('.modal-dialog').find('.close').click();
        }
        $('#order_ids').val(sel_order.join(','));
    }


</script>
